package com.initialize.common.tool.util;

import com.initialize.commom.config.header.HeaderConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;

import javax.annotation.PostConstruct;

/**
 * Created with IntelliJ IDEA.
 * User: jane
 * Date: 2020/1/10
 * Time: 1:37 下午
 * Description: 核心的工具
 */
@Slf4j
@Component
public class CoreTool {


    private static Jedis jedis;

    @Autowired
    Jedis jedi;

    @PostConstruct
    private void initJedis() {
        jedis = this.jedi;
    }

    /**
     * 创建一个内部访问的令牌,用于RestTemplate转发
     *
     * @return HttpHeaders
     */
    public static HttpHeaders createHttpHeaders() {
        String uuidNo_ = RandomTool.createUuidNo_();
        jedis.sadd(HeaderConfig.INTERNAL_SECRET_KEY, uuidNo_);
        HttpHeaders headers = new HttpHeaders();
        headers.add(HeaderConfig.INTERNAL_SECRET_KEY, uuidNo_);
        return headers;
    }
}